home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / sml_nj / 93src.lha / src / runtime / malloc.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-02-09  |  1002 b   |  58 lines

  1. /* malloc.c
  2.  *
  3.  * COPYRIGHT (c) 1990 by AT&T Bell Laboratories.
  4.  *
  5.  * Versions of malloc, realloc, calloc, free and cfree that can live with ML.
  6.  */
  7.  
  8. #ifndef NeXT /* The NeXT can use the system malloc */
  9.  
  10. #if defined(SGI) || defined(ADVICE)
  11. /* need malloc routines for SGI multi-processor library. */
  12.  
  13. #define HEAP_SZ        0x10000        /* 64K */
  14.  
  15. static char mallocbuf[HEAP_SZ], *mallocptr=mallocbuf;
  16.  
  17. char *malloc (n)
  18.     int        n;
  19. {
  20.     char    *p;
  21.  
  22.     n = (n+3) & ~3;
  23.     if (mallocptr+n > mallocbuf+HEAP_SZ)
  24.     die ("Too much malloc.");
  25.     p = mallocptr;
  26.     mallocptr += n;
  27.     return p;
  28. }
  29.  
  30. void free () {}
  31.  
  32. char *realloc ()
  33. {
  34.     die ("Didn't expect realloc.");
  35. }
  36.  
  37. char *calloc (n, m)
  38.     int        n,m; 
  39. {
  40.     char    *p = malloc(n*m);
  41.     int        i;
  42.  
  43.     for(i=0; i<n; i++)
  44.     p[i]=0;
  45.     return p;
  46. }
  47.  
  48. void cfree () {}
  49.  
  50. #else
  51. char *malloc () { die ("malloc"); }
  52. char *realloc () { die ("realloc"); }
  53. char *calloc () { die ("calloc"); }
  54. void free () { die ("free"); }
  55. void cfree () { die ("cfree"); }
  56. #endif
  57. #endif !NeXT
  58.